/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.designtime.api.operation.CommonValidation;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.DataTypeValidationsGenCtx;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base.Methods.ValCanExecuteGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base.Methods.ValExecuteGenerator;
import com.inspur.edp.cef.spi.validation.IValidation;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public abstract class BaseValGenerator extends ClassGenerator {
  protected DataTypeValidationsGenCtx valsGenCtx;
  private CommonValidation validation;

  protected BaseValGenerator(DataTypeValidationsGenCtx valsGenCtx, CommonValidation validation) {
    super(valsGenCtx.getDataTypeImplGenCtx().getParentContext().getProjContext().getCompilationUnitInfo());
    this.valsGenCtx = valsGenCtx;
    this.validation = validation;
  }


  // keyword:
  // ORIGINAL LINE: protected new BaseValGenCtx getContext() { return
  // (BaseValGenCtx)super.getContext(); }
  @Override
  protected com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base.BaseValGenCtx getContext() {
    return (com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base.BaseValGenCtx) super.getContext();
  }

  @Override
  protected ClassGeneratorContext createClassInfoContext() {
    return new com.inspur.edp.cef.generator.coreGenerator.base.entitygen.validation.base.BaseValGenCtx(valsGenCtx, validation);
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifier() {
    return new java.util.ArrayList<ModifierKeyword>(
        java.util.Arrays.asList(new ModifierKeyword[] {ModifierKeyword.PUBLIC_KEYWORD}));
  }

  protected abstract String getValidationType();

  public String getItemName() {
    return getName();
  }

  private static final String nameSuffix = "ValAdaptor";

  @Override
  protected String getName() {
    return valsGenCtx.getDataTypeImplGenCtx().getDataType().getCode()
        + getValidationType()
        + validation.getCode()
        + nameSuffix;
  }

  @Override
  protected ArrayList<TypeInfo> addParentInterfaces() {
    return new java.util.ArrayList<TypeInfo>(
        java.util.Arrays.asList(new TypeInfo[] {new TypeInfo(IValidation.class)}));
  }

  @Override
  protected java.util.ArrayList<ClassMethodGenerator> createMethodGenerators() {
    java.util.ArrayList<ClassMethodGenerator> list = super.createMethodGenerators();
    if (list == null) {
      list = new java.util.ArrayList<ClassMethodGenerator>();
    }
    list.add(getCanExecuteGenerator());
    list.add(getExecuteGenerator());
    return list;
  }

  protected abstract ValCanExecuteGenerator getCanExecuteGenerator();

  protected abstract ValExecuteGenerator getExecuteGenerator();
}
